From 83b8b65996378ae59922375ca1565e2aaf7917c0 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 30 Jun 2005 18:39:54 +0000 Subject: [PATCH] Move iso8859_1_to_utf8 into common code. --- gpsbabel/bcr.c | 42 ------------------------------------------ gpsbabel/defs.h | 10 ++++++++-- gpsbabel/util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/gpsbabel/bcr.c b/gpsbabel/bcr.c index 06ba79cfb..0ef698e81 100644 --- a/gpsbabel/bcr.c +++ b/gpsbabel/bcr.c @@ -124,44 +124,6 @@ bcr_find_waypt(const char *name, route_head *route) /* find a waypt by name, cr return wpt; } -#ifndef UTF8_SUPPORT -char * -bcr_iso8859_1_to_utf8(const char *s) -{ - int len; - char *res; - unsigned char c; - char *src, *dst; - - if (s == NULL) return NULL; - - len = 0; - src = (char *)s; - while ('\0' != (c = *src++)) - { - len++; - if (c & 0x80) len++; - } - - src = (char *)s; - dst = res = (void *) xmalloc(len + 1); - while ('\0' != (c = *src++)) - { - if (c & 0x80) - { - *dst++ = (0xc0 | (c >> 6)); - *dst++ = (c & 0xbf); - } - else - { - *dst++ = c; - } - } - *dst = '\0'; - return res; -} -#endif - void bcr_create_waypts_from_route(route_head *route) { @@ -281,11 +243,7 @@ bcr_data_read(void) } if (src != NULL) xfree(src); -#ifdef UTF8_SUPPORT src = str_iso8859_1_to_utf8(buff); -#else - src = bcr_iso8859_1_to_utf8(buff); /* internal copy str_iso8859_1_to_utf8 */ -#endif /* !! buff is now free and can be used */ c = bcr_next_char(src); /* skip spaces */ diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 96ef6a61f..72c5ce53a 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -564,8 +564,14 @@ char * xml_entitize(const char * str); char * html_entitize(const char * str); char * strip_html(const utf_string*); char * strip_nastyhtml(const char * in); -char * str_utf8_to_cp1252( const char * str ); -char * str_utf8_to_ascii( const char * str ); + +/* + * Character encoding transformations. + */ +char * str_utf8_to_cp1252(const char * str); +char * str_utf8_to_ascii(const char * str); +char * str_iso8859_1_to_utf8(const char *str ); + /* this lives in gpx.c */ time_t xml_parse_time( const char *cdatastr ); diff --git a/gpsbabel/util.c b/gpsbabel/util.c index cb9a689df..654eeefbc 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -952,6 +952,48 @@ char * str_utf8_to_ascii( const char * str ) return result; } +/* + * str_iso8859_1_to_utf8 + * + * converts the single byte charset ISO8859-1 (latin1) to UTF-8 + */ + +char * +str_iso8859_1_to_utf8(const char *s) +{ + int len; + char *res; + unsigned char c; + char *src, *dst; + + if (s == NULL) return NULL; + + len = 0; + src = (char *)s; + while ('\0' != (c = *src++)) + { + len++; + if (c & 0x80) len++; + } + + src = (char *)s; + dst = res = (void *) xmalloc(len + 1); + while ('\0' != (c = *src++)) + { + if (c & 0x80) + { + *dst++ = (0xc0 | (c >> 6)); + *dst++ = (c & 0xbf); + } + else + { + *dst++ = c; + } + } + *dst = '\0'; + return res; +} + /* * Get rid of potentially nasty HTML that would influence another record * that includes; -- 2.30.2